package GM.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

import GM.GMPackage;
import GM.diagram.edit.parts.ActionEditPart;
import GM.diagram.edit.parts.AdGoalActionsEditPart;
import GM.diagram.edit.parts.AdGoalEditPart;
import GM.diagram.edit.parts.AdGoalHelpEditPart;
import GM.diagram.edit.parts.AgentEditPart;
import GM.diagram.edit.parts.AgentOperatEditPart;
import GM.diagram.edit.parts.Attribute2EditPart;
import GM.diagram.edit.parts.AttributeEditPart;
import GM.diagram.edit.parts.ContributionLinkEditPart;
import GM.diagram.edit.parts.Definition2EditPart;
import GM.diagram.edit.parts.Definition3EditPart;
import GM.diagram.edit.parts.Definition4EditPart;
import GM.diagram.edit.parts.Definition5EditPart;
import GM.diagram.edit.parts.Definition6EditPart;
import GM.diagram.edit.parts.Definition7EditPart;
import GM.diagram.edit.parts.Definition8EditPart;
import GM.diagram.edit.parts.DefinitionEditPart;
import GM.diagram.edit.parts.EntityEditPart;
import GM.diagram.edit.parts.EventEditPart;
import GM.diagram.edit.parts.GoalDiagramEditPart;
import GM.diagram.edit.parts.GoalEditPart;
import GM.diagram.edit.parts.GoalOperatEditPart;
import GM.diagram.edit.parts.GoalRefEditPart;
import GM.diagram.edit.parts.Mapping2EditPart;
import GM.diagram.edit.parts.Mapping3EditPart;
import GM.diagram.edit.parts.Mapping4EditPart;
import GM.diagram.edit.parts.Mapping5EditPart;
import GM.diagram.edit.parts.Mapping6EditPart;
import GM.diagram.edit.parts.Mapping7EditPart;
import GM.diagram.edit.parts.Mapping8EditPart;
import GM.diagram.edit.parts.MappingEditPart;
import GM.diagram.edit.parts.OperationEditPart;
import GM.diagram.edit.parts.Reference2EditPart;
import GM.diagram.edit.parts.ReferenceEditPart;
import GM.diagram.edit.parts.ReferenceTypeEditPart;
import GM.diagram.edit.parts.RefinementLinkEditPart;
import GM.diagram.edit.parts.RefinementLinkTargetEditPart;
import GM.diagram.edit.parts.StateEditPart;
import GM.diagram.part.GMDiagramEditorPlugin;

/**
 * @generated
 */
public class GMElementTypes {

	/**
	 * @generated
	 */
	private GMElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map<IElementType, ENamedElement> elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set<IElementType> KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType GoalDiagram_1000 = getElementType("project.goal.diagram.GoalDiagram_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Goal_2001 = getElementType("project.goal.diagram.Goal_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AdGoal_2002 = getElementType("project.goal.diagram.AdGoal_2002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operation_2003 = getElementType("project.goal.diagram.Operation_2003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Entity_2004 = getElementType("project.goal.diagram.Entity_2004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Event_2005 = getElementType("project.goal.diagram.Event_2005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Action_2006 = getElementType("project.goal.diagram.Action_2006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Agent_2007 = getElementType("project.goal.diagram.Agent_2007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType RefinementLink_2008 = getElementType("project.goal.diagram.RefinementLink_2008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3031 = getElementType("project.goal.diagram.Definition_3031"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3044 = getElementType("project.goal.diagram.Mapping_3044"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3032 = getElementType("project.goal.diagram.Definition_3032"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3045 = getElementType("project.goal.diagram.Mapping_3045"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3033 = getElementType("project.goal.diagram.Definition_3033"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3046 = getElementType("project.goal.diagram.Mapping_3046"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3034 = getElementType("project.goal.diagram.Definition_3034"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3047 = getElementType("project.goal.diagram.Mapping_3047"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3035 = getElementType("project.goal.diagram.Definition_3035"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3048 = getElementType("project.goal.diagram.Mapping_3048"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3036 = getElementType("project.goal.diagram.Definition_3036"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3049 = getElementType("project.goal.diagram.Mapping_3049"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3037 = getElementType("project.goal.diagram.Definition_3037"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3050 = getElementType("project.goal.diagram.Mapping_3050"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Definition_3038 = getElementType("project.goal.diagram.Definition_3038"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Mapping_3051 = getElementType("project.goal.diagram.Mapping_3051"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Attribute_3039 = getElementType("project.goal.diagram.Attribute_3039"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Reference_3040 = getElementType("project.goal.diagram.Reference_3040"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType State_3041 = getElementType("project.goal.diagram.State_3041"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Attribute_3042 = getElementType("project.goal.diagram.Attribute_3042"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Reference_3043 = getElementType("project.goal.diagram.Reference_3043"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AdGoalHelp_4001 = getElementType("project.goal.diagram.AdGoalHelp_4001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AgentOperat_4002 = getElementType("project.goal.diagram.AgentOperat_4002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType GoalRef_4003 = getElementType("project.goal.diagram.GoalRef_4003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType RefinementLinkTarget_4004 = getElementType("project.goal.diagram.RefinementLinkTarget_4004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType GoalOperat_4005 = getElementType("project.goal.diagram.GoalOperat_4005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AdGoalActions_4006 = getElementType("project.goal.diagram.AdGoalActions_4006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ContributionLink_4007 = getElementType("project.goal.diagram.ContributionLink_4007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ReferenceType_4011 = getElementType("project.goal.diagram.ReferenceType_4011"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return GMDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap<IElementType, ENamedElement>();

			elements.put(GoalDiagram_1000, GMPackage.eINSTANCE.getGoalDiagram());

			elements.put(Goal_2001, GMPackage.eINSTANCE.getGoal());

			elements.put(AdGoal_2002, GMPackage.eINSTANCE.getAdGoal());

			elements.put(Operation_2003, GMPackage.eINSTANCE.getOperation());

			elements.put(Entity_2004, GMPackage.eINSTANCE.getEntity());

			elements.put(Event_2005, GMPackage.eINSTANCE.getEvent());

			elements.put(Action_2006, GMPackage.eINSTANCE.getAction());

			elements.put(Agent_2007, GMPackage.eINSTANCE.getAgent());

			elements.put(RefinementLink_2008,
					GMPackage.eINSTANCE.getRefinementLink());

			elements.put(Definition_3031, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3044, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3032, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3045, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3033, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3046, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3034, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3047, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3035, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3048, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3036, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3049, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3037, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3050, GMPackage.eINSTANCE.getMapping());

			elements.put(Definition_3038, GMPackage.eINSTANCE.getDefinition());

			elements.put(Mapping_3051, GMPackage.eINSTANCE.getMapping());

			elements.put(Attribute_3039, GMPackage.eINSTANCE.getAttribute());

			elements.put(Reference_3040, GMPackage.eINSTANCE.getReference());

			elements.put(State_3041, GMPackage.eINSTANCE.getState());

			elements.put(Attribute_3042, GMPackage.eINSTANCE.getAttribute());

			elements.put(Reference_3043, GMPackage.eINSTANCE.getReference());

			elements.put(AdGoalHelp_4001, GMPackage.eINSTANCE.getAdGoal_Help());

			elements.put(AgentOperat_4002,
					GMPackage.eINSTANCE.getAgent_Operat());

			elements.put(GoalRef_4003, GMPackage.eINSTANCE.getGoal_Ref());

			elements.put(RefinementLinkTarget_4004,
					GMPackage.eINSTANCE.getRefinementLink_Target());

			elements.put(GoalOperat_4005, GMPackage.eINSTANCE.getGoal_Operat());

			elements.put(AdGoalActions_4006,
					GMPackage.eINSTANCE.getAdGoal_Actions());

			elements.put(ContributionLink_4007,
					GMPackage.eINSTANCE.getContributionLink());

			elements.put(ReferenceType_4011,
					GMPackage.eINSTANCE.getReference_Type());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet<IElementType>();
			KNOWN_ELEMENT_TYPES.add(GoalDiagram_1000);
			KNOWN_ELEMENT_TYPES.add(Goal_2001);
			KNOWN_ELEMENT_TYPES.add(AdGoal_2002);
			KNOWN_ELEMENT_TYPES.add(Operation_2003);
			KNOWN_ELEMENT_TYPES.add(Entity_2004);
			KNOWN_ELEMENT_TYPES.add(Event_2005);
			KNOWN_ELEMENT_TYPES.add(Action_2006);
			KNOWN_ELEMENT_TYPES.add(Agent_2007);
			KNOWN_ELEMENT_TYPES.add(RefinementLink_2008);
			KNOWN_ELEMENT_TYPES.add(Definition_3031);
			KNOWN_ELEMENT_TYPES.add(Mapping_3044);
			KNOWN_ELEMENT_TYPES.add(Definition_3032);
			KNOWN_ELEMENT_TYPES.add(Mapping_3045);
			KNOWN_ELEMENT_TYPES.add(Definition_3033);
			KNOWN_ELEMENT_TYPES.add(Mapping_3046);
			KNOWN_ELEMENT_TYPES.add(Definition_3034);
			KNOWN_ELEMENT_TYPES.add(Mapping_3047);
			KNOWN_ELEMENT_TYPES.add(Definition_3035);
			KNOWN_ELEMENT_TYPES.add(Mapping_3048);
			KNOWN_ELEMENT_TYPES.add(Definition_3036);
			KNOWN_ELEMENT_TYPES.add(Mapping_3049);
			KNOWN_ELEMENT_TYPES.add(Definition_3037);
			KNOWN_ELEMENT_TYPES.add(Mapping_3050);
			KNOWN_ELEMENT_TYPES.add(Definition_3038);
			KNOWN_ELEMENT_TYPES.add(Mapping_3051);
			KNOWN_ELEMENT_TYPES.add(Attribute_3039);
			KNOWN_ELEMENT_TYPES.add(Reference_3040);
			KNOWN_ELEMENT_TYPES.add(State_3041);
			KNOWN_ELEMENT_TYPES.add(Attribute_3042);
			KNOWN_ELEMENT_TYPES.add(Reference_3043);
			KNOWN_ELEMENT_TYPES.add(AdGoalHelp_4001);
			KNOWN_ELEMENT_TYPES.add(AgentOperat_4002);
			KNOWN_ELEMENT_TYPES.add(GoalRef_4003);
			KNOWN_ELEMENT_TYPES.add(RefinementLinkTarget_4004);
			KNOWN_ELEMENT_TYPES.add(GoalOperat_4005);
			KNOWN_ELEMENT_TYPES.add(AdGoalActions_4006);
			KNOWN_ELEMENT_TYPES.add(ContributionLink_4007);
			KNOWN_ELEMENT_TYPES.add(ReferenceType_4011);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case GoalDiagramEditPart.VISUAL_ID:
			return GoalDiagram_1000;
		case GoalEditPart.VISUAL_ID:
			return Goal_2001;
		case AdGoalEditPart.VISUAL_ID:
			return AdGoal_2002;
		case OperationEditPart.VISUAL_ID:
			return Operation_2003;
		case EntityEditPart.VISUAL_ID:
			return Entity_2004;
		case EventEditPart.VISUAL_ID:
			return Event_2005;
		case ActionEditPart.VISUAL_ID:
			return Action_2006;
		case AgentEditPart.VISUAL_ID:
			return Agent_2007;
		case RefinementLinkEditPart.VISUAL_ID:
			return RefinementLink_2008;
		case DefinitionEditPart.VISUAL_ID:
			return Definition_3031;
		case MappingEditPart.VISUAL_ID:
			return Mapping_3044;
		case Definition2EditPart.VISUAL_ID:
			return Definition_3032;
		case Mapping2EditPart.VISUAL_ID:
			return Mapping_3045;
		case Definition3EditPart.VISUAL_ID:
			return Definition_3033;
		case Mapping3EditPart.VISUAL_ID:
			return Mapping_3046;
		case Definition4EditPart.VISUAL_ID:
			return Definition_3034;
		case Mapping4EditPart.VISUAL_ID:
			return Mapping_3047;
		case Definition5EditPart.VISUAL_ID:
			return Definition_3035;
		case Mapping5EditPart.VISUAL_ID:
			return Mapping_3048;
		case Definition6EditPart.VISUAL_ID:
			return Definition_3036;
		case Mapping6EditPart.VISUAL_ID:
			return Mapping_3049;
		case Definition7EditPart.VISUAL_ID:
			return Definition_3037;
		case Mapping7EditPart.VISUAL_ID:
			return Mapping_3050;
		case Definition8EditPart.VISUAL_ID:
			return Definition_3038;
		case Mapping8EditPart.VISUAL_ID:
			return Mapping_3051;
		case AttributeEditPart.VISUAL_ID:
			return Attribute_3039;
		case ReferenceEditPart.VISUAL_ID:
			return Reference_3040;
		case StateEditPart.VISUAL_ID:
			return State_3041;
		case Attribute2EditPart.VISUAL_ID:
			return Attribute_3042;
		case Reference2EditPart.VISUAL_ID:
			return Reference_3043;
		case AdGoalHelpEditPart.VISUAL_ID:
			return AdGoalHelp_4001;
		case AgentOperatEditPart.VISUAL_ID:
			return AgentOperat_4002;
		case GoalRefEditPart.VISUAL_ID:
			return GoalRef_4003;
		case RefinementLinkTargetEditPart.VISUAL_ID:
			return RefinementLinkTarget_4004;
		case GoalOperatEditPart.VISUAL_ID:
			return GoalOperat_4005;
		case AdGoalActionsEditPart.VISUAL_ID:
			return AdGoalActions_4006;
		case ContributionLinkEditPart.VISUAL_ID:
			return ContributionLink_4007;
		case ReferenceTypeEditPart.VISUAL_ID:
			return ReferenceType_4011;
		}
		return null;
	}

}
